* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    /* 防止移动端字体自动缩放 */
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
    background-attachment: fixed;
    color: #e2e8f0;
    font-size: 12px;
    line-height: 1.4;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    /* 移动端优化 */
    -webkit-overflow-scrolling: touch;
    min-height: 100vh;
}

.container {
    width: 100%;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 4px;
    gap: 4px;
}

/* ========== 顶部栏 ========== */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, #1e293b 0%, #2d3748 100%);
    padding: 6px 12px;
    border-radius: 6px;
    border-bottom: 2px solid #3b82f6;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

.title-section {
    display: flex;
    align-items: baseline;
    gap: 12px;
}

.title-section h1 {
    font-size: 1.3em;
    font-weight: 700;
    background: linear-gradient(135deg, #3b82f6 0%, #60a5fa 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: 0.5px;
}

.last-update {
    font-size: 0.85em;
    color: #64748b;
}

.account-cards {
    display: flex;
    gap: 16px;
}

.account-card {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
}

.account-card .label {
    font-size: 0.75em;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.account-card .value {
    font-size: 1.4em;
    font-weight: 700;
    color: #e2e8f0;
}

.account-card .value.positive {
    color: #ef4444; /* 红色表示盈利/上涨 */
}

.account-card .value.negative {
    color: #10b981; /* 绿色表示亏损/下跌 */
}

/* ========== 主网格布局 ========== */
.main-grid {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 4px;
    min-height: 0;
}

.left-panel,
.middle-panel,
.right-panel {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-height: 0;
}

/* ========== 面板通用样式 ========== */
.panel {
    background: linear-gradient(135deg, #1e293b 0%, #2d3748 100%);
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    min-height: 0;
    border: 1px solid #334155;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: box-shadow 0.3s ease;
    overflow: hidden;
}

.panel:hover {
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.panel-header {
    padding: 6px 10px;
    font-size: 0.95em;
    font-weight: 600;
    color: #94a3b8;
    border-bottom: 1px solid #334155;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: linear-gradient(135deg, #1a2332 0%, #1e293b 100%);
    border-radius: 6px 6px 0 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-shrink: 0;
}

.panel-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 6px;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    scroll-behavior: smooth;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* 美化滚动条 */
.panel-body::-webkit-scrollbar {
    width: 4px;
}

.panel-body::-webkit-scrollbar-track {
    background: #1e293b;
}

.panel-body::-webkit-scrollbar-thumb {
    background: #475569;
    border-radius: 2px;
}

.panel-body::-webkit-scrollbar-thumb:hover {
    background: #64748b;
}

/* ========== 左侧面板 ========== */
.chart-panel {
    flex: 1.5;
    min-height: 150px;
}

.chart-panel .panel-body {
    padding: 8px;
}

.stats-panel {
    flex: 1;
    min-height: 100px;
}

/* 交易统计表格 */
.stats-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95em;
    table-layout: fixed;
}

.stats-table tr {
    border-bottom: 1px solid #2d3748;
    transition: background 0.2s ease;
}

.stats-table tr:hover {
    background: rgba(59, 130, 246, 0.05);
}

.stats-table tr:last-child {
    border-bottom: none;
}

.stats-table td {
    padding: 4px 6px;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.stats-table td:first-child {
    color: #94a3b8;
    width: 55%;
}

.stats-table td:last-child {
    color: #e2e8f0;
    font-weight: 600;
    text-align: right;
}

.stats-table .positive {
    color: #ef4444; /* 红色表示盈利 */
}

.stats-table .negative {
    color: #10b981; /* 绿色表示亏损 */
}

/* ========== 中间面板（持仓） ========== */
.positions-panel {
    flex: 1;
}

.position-item {
    background: linear-gradient(135deg, #2d3748 0%, #334155 100%);
    border-radius: 6px;
    padding: 6px 8px;
    margin-bottom: 6px;
    border-left: 3px solid #3b82f6;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    transition: all 0.2s ease;
}

.position-item:hover {
    transform: translateX(2px);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.position-item.long {
    border-left-color: #ef4444; /* 红色表示做多 */
    background: linear-gradient(135deg, #3a1e1e 0%, #2d3748 100%);
}

.position-item.short {
    border-left-color: #10b981; /* 绿色表示做空 */
    background: linear-gradient(135deg, #1e3a2a 0%, #2d3748 100%);
}

.position-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
    padding-bottom: 4px;
    border-bottom: 1px solid #3f4b5f;
}

.position-symbol {
    font-size: 1.1em;
    font-weight: 700;
    color: #f1f5f9;
}

.position-side {
    padding: 2px 8px;
    border-radius: 3px;
    color: white;
    font-weight: 600;
    font-size: 0.75em;
}

.position-side.long {
    background: #ef4444; /* 红色表示做多 */
}

.position-side.short {
    background: #10b981; /* 绿色表示做空 */
}

.position-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px 4px;
}

.position-field {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.position-field .label {
    font-size: 0.75em;
    color: #64748b;
}

.position-field .value {
    font-size: 0.9em;
    font-weight: 600;
    color: #e2e8f0;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.position-field .value.positive {
    color: #ef4444; /* 红色表示盈利 */
}

.position-field .value.negative {
    color: #10b981; /* 绿色表示亏损 */
}

/* ========== 右侧面板 ========== */
.trades-panel {
    flex: 1;
}

.logs-panel {
    flex: 1;
}

/* 交易记录 */
.trade-item {
    background: linear-gradient(135deg, #2d3748 0%, #334155 100%);
    border-radius: 5px;
    padding: 5px 6px;
    margin-bottom: 4px;
    font-size: 0.9em;
    border-left: 2px solid #475569;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
    transition: all 0.2s ease;
}

.trade-item:hover {
    transform: translateX(2px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
}

.trade-item.trade-warning {
    background: linear-gradient(135deg, #422006 0%, #4a2b0f 100%);
    border-left-color: #f59e0b;
    box-shadow: 0 1px 3px rgba(245, 158, 11, 0.2);
}

.trade-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 3px;
}

.trade-time {
    font-size: 0.75em;
    color: #64748b;
}

.trade-pnl {
    font-weight: 700;
    font-size: 0.95em;
}

.trade-pnl.positive {
    color: #ef4444; /* 红色表示盈利 */
}

.trade-pnl.negative {
    color: #10b981; /* 绿色表示亏损 */
}

.trade-pnl.neutral {
    color: #94a3b8;
}

.trade-info {
    color: #cbd5e1;
    font-size: 0.85em;
    line-height: 1.3;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.trade-symbol {
    color: #f1f5f9;
    font-weight: 600;
}

.trade-side {
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 3px;
}

.trade-side.long {
    color: #ef4444; /* 红色表示做多 */
    background: rgba(239, 68, 68, 0.1);
}

.trade-side.short {
    color: #10b981; /* 绿色表示做空 */
    background: rgba(16, 185, 129, 0.1);
}

.trade-fee {
    color: #f59e0b;
    font-size: 0.85em;
    margin-left: 6px;
}

.trade-warning-msg {
    background: #422006;
    color: #fbbf24;
    padding: 3px 6px;
    margin-top: 3px;
    border-radius: 2px;
    font-size: 0.75em;
    border-left: 2px solid #f59e0b;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.trade-field {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 2px 0;
    font-size: 0.8em;
}

.trade-field .label {
    color: #64748b;
    font-size: 0.9em;
}

.trade-field .value {
    color: #e2e8f0;
    font-weight: 600;
}

.trade-field .value.long {
    color: #ef4444;
}

.trade-field .value.short {
    color: #10b981;
}

.trade-field .value.profit {
    color: #ef4444; /* 红色表示盈利 */
}

.trade-field .value.loss {
    color: #10b981; /* 绿色表示亏损 */
}

/* AI 决策日志 */
.log-item {
    background: linear-gradient(135deg, #2d3748 0%, #334155 100%);
    border-radius: 5px;
    padding: 6px;
    margin-bottom: 6px;
    border-left: 2px solid #3b82f6;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
    transition: all 0.2s ease;
}

.log-item:hover {
    transform: translateX(2px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
    border-left-color: #60a5fa;
}

.log-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
    padding-bottom: 3px;
    border-bottom: 1px solid #3f4b5f;
}

.log-time {
    font-size: 0.75em;
    color: #64748b;
}

.log-iteration {
    font-size: 0.75em;
    color: #3b82f6;
    font-weight: 600;
}

.copy-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #64748b;
    transition: all 0.2s ease;
    border-radius: 3px;
    opacity: 0.7;
}

.copy-btn:hover {
    color: #3b82f6;
    background: rgba(59, 130, 246, 0.1);
    opacity: 1;
}

.copy-btn:active {
    transform: scale(0.95);
}

.copy-btn svg {
    display: block;
}

.log-decision {
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.8em;
    color: #cbd5e1;
    line-height: 1.4;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* ========== 加载和空状态 ========== */
.loading,
.no-data {
    text-align: center;
    color: #475569;
    padding: 20px;
    font-size: 0.9em;
}

.loading {
    position: relative;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 0.6;
    }
    50% {
        opacity: 1;
    }
}

/* ========== 响应式设计 ========== */

/* 大屏优化 */
@media (min-width: 1920px) {
    body {
        font-size: 14px;
    }
    
    .panel-header {
        font-size: 1.05em;
        padding: 8px 12px;
    }
    
    .panel-body {
        padding: 10px;
    }
}

/* 大屏幕 - 桌面端保持固定高度 */
@media (min-width: 1025px) {
    body {
        overflow: hidden;
        height: 100vh;
    }
    
    .container {
        height: 100vh;
        min-height: auto;
    }
    
    .main-grid {
        max-height: calc(100vh - 60px);
        overflow: hidden;
    }
    
    .left-panel,
    .middle-panel,
    .right-panel {
        max-height: 100%;
        overflow: hidden;
    }
    
    .panel {
        max-height: 100%;
    }
    
    .panel-body {
        max-height: 100%;
    }
}

/* 平板横屏 */
@media (max-width: 1400px) and (min-width: 1025px) {
    .main-grid {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: 1fr 1fr;
        max-height: calc(100vh - 70px);
    }
    
    .left-panel {
        grid-column: 1;
        grid-row: 1;
    }
    
    .middle-panel {
        grid-column: 2;
        grid-row: 1;
    }
    
    .right-panel {
        grid-column: 1 / -1;
        grid-row: 2;
        flex-direction: row;
    }
    
    .right-panel .panel {
        flex: 1;
    }
}

/* 平板竖屏 */
@media (max-width: 1024px) {
    body {
        font-size: 11px;
    }
    
    .container {
        padding: 6px;
        gap: 6px;
    }
    
    .top-bar {
        padding: 8px 10px;
    }
    
    .main-grid {
        grid-template-columns: 1fr;
        grid-template-rows: auto;
        max-height: none;
    }
    
    .left-panel,
    .middle-panel,
    .right-panel {
        grid-column: 1;
        min-height: 220px;
        max-height: none;
    }
    
    .right-panel {
        flex-direction: column;
    }
    
    .account-cards {
        gap: 8px;
    }
    
    .chart-panel {
        min-height: 180px;
    }
    
    .panel {
        max-height: 80vh;
    }
    
    .panel-body {
        max-height: calc(80vh - 40px);
    }
}

/* 手机横屏 */
@media (max-width: 768px) {
    body {
        font-size: 11.5px;
    }
    
    .container {
        padding: 4px;
        gap: 4px;
    }
    
    .top-bar {
        flex-direction: column;
        gap: 8px;
        align-items: stretch;
        padding: 8px;
    }
    
    .title-section {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        gap: 10px;
    }
    
    .title-section h1 {
        font-size: 1.3em;
    }
    
    .last-update {
        font-size: 0.8em;
        white-space: nowrap;
    }
    
    .account-cards {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
        width: 100%;
    }
    
    .account-card {
        background: #2d3748;
        padding: 8px 10px;
        border-radius: 6px;
        align-items: flex-start;
        border-left: 3px solid #3b82f6;
        min-height: 50px;
        justify-content: space-between;
        transition: all 0.2s ease;
    }
    
    .account-card:active {
        transform: scale(0.98);
        background: #334155;
    }
    
    .account-card .label {
        font-size: 0.75em;
        margin-bottom: 2px;
    }
    
    .account-card .value {
        font-size: 1.3em;
    }
    
    .main-grid {
        gap: 4px;
    }
    
    .panel {
        border-radius: 8px;
    }
    
    .panel-header {
        font-size: 0.9em;
        padding: 8px 10px;
        border-radius: 8px 8px 0 0;
    }
    
    .panel-body {
        padding: 8px;
    }
    
    .position-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 6px 4px;
    }
    
    .chart-panel {
        min-height: 220px;
        max-height: none;
    }
    
    .stats-panel,
    .trades-panel,
    .logs-panel,
    .positions-panel {
        min-height: 180px;
        max-height: 70vh;
    }
    
    .left-panel,
    .middle-panel,
    .right-panel {
        max-height: none;
    }
    
    .stats-panel .panel-body,
    .trades-panel .panel-body,
    .logs-panel .panel-body,
    .positions-panel .panel-body {
        max-height: calc(70vh - 40px);
    }
    
    /* 增加可触摸区域 */
    .position-item,
    .trade-item,
    .log-item {
        min-height: 44px;
        cursor: pointer;
    }
    
    .position-item:active,
    .trade-item:active,
    .log-item:active {
        transform: scale(0.98);
        opacity: 0.9;
    }
}

/* 手机竖屏 */
@media (max-width: 480px) {
    body {
        font-size: 11px;
    }
    
    .container {
        padding: 4px;
        gap: 4px;
    }
    
    .top-bar {
        padding: 8px;
        gap: 8px;
        border-radius: 8px;
    }
    
    .title-section {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }
    
    .title-section h1 {
        font-size: 1.2em;
    }
    
    .last-update {
        font-size: 0.75em;
    }
    
    .account-cards {
        grid-template-columns: repeat(2, 1fr);
        gap: 6px;
    }
    
    .account-card {
        padding: 8px;
        min-height: 55px;
    }
    
    .account-card .label {
        font-size: 0.7em;
    }
    
    .account-card .value {
        font-size: 1.2em;
    }
    
    .main-grid {
        gap: 4px;
    }
    
    .panel {
        border-radius: 8px;
    }
    
    .panel-header {
        font-size: 0.85em;
        padding: 8px;
        border-radius: 8px 8px 0 0;
    }
    
    .panel-body {
        padding: 8px;
    }
    
    .position-item {
        padding: 8px;
        margin-bottom: 6px;
        border-radius: 8px;
        border-left-width: 4px;
    }
    
    .position-header {
        margin-bottom: 6px;
        padding-bottom: 4px;
    }
    
    .position-symbol {
        font-size: 1em;
    }
    
    .position-side {
        font-size: 0.75em;
        padding: 3px 8px;
    }
    
    .position-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 6px 4px;
    }
    
    .position-field .label {
        font-size: 0.75em;
    }
    
    .position-field .value {
        font-size: 0.9em;
    }
    
    .trade-item {
        padding: 8px;
        margin-bottom: 6px;
        font-size: 0.9em;
        border-radius: 8px;
    }
    
    .trade-header {
        margin-bottom: 4px;
    }
    
    .trade-time {
        font-size: 0.75em;
    }
    
    .trade-pnl {
        font-size: 1em;
    }
    
    .trade-info {
        font-size: 0.85em;
        line-height: 1.4;
    }
    
    .log-item {
        padding: 8px;
        margin-bottom: 6px;
        border-radius: 8px;
    }
    
    .log-header {
        margin-bottom: 4px;
        padding-bottom: 3px;
    }
    
    .log-time,
    .log-iteration {
        font-size: 0.75em;
    }
    
    .log-decision {
        font-size: 0.8em;
        line-height: 1.5;
    }
    
    .stats-table {
        font-size: 0.95em;
    }
    
    .stats-table td {
        padding: 6px;
    }
    
    .chart-panel {
        min-height: 200px;
        max-height: none;
    }
    
    .stats-panel {
        min-height: 180px;
        max-height: none;
    }
    
    .left-panel,
    .middle-panel,
    .right-panel {
        min-height: 180px;
        max-height: none;
    }
    
    .trades-panel,
    .logs-panel,
    .positions-panel {
        min-height: 200px;
        max-height: 70vh;
    }
    
    .trades-panel .panel-body,
    .logs-panel .panel-body,
    .positions-panel .panel-body {
        max-height: calc(70vh - 40px);
    }
}

/* 超小屏幕 */
@media (max-width: 360px) {
    body {
        font-size: 10px;
    }
    
    .container {
        padding: 3px;
        gap: 3px;
    }
    
    .top-bar {
        padding: 6px;
        gap: 6px;
    }
    
    .title-section h1 {
        font-size: 1.1em;
    }
    
    .account-cards {
        grid-template-columns: 1fr;
        gap: 5px;
    }
    
    .account-card {
        padding: 6px 8px;
        min-height: 50px;
    }
    
    .panel-header {
        padding: 6px 8px;
    }
    
    .panel-body {
        padding: 6px;
    }
    
    .position-grid {
        grid-template-columns: 1fr;
        gap: 5px;
    }
    
    .position-item,
    .trade-item,
    .log-item {
        padding: 6px;
    }
    
    .panel {
        max-height: 70vh;
    }
    
    .panel-body {
        max-height: calc(70vh - 35px);
    }
}

/* 横屏模式优化 */
@media (max-height: 500px) and (orientation: landscape) {
    .main-grid {
        grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
        grid-template-rows: auto;
        max-height: none;
    }
    
    .left-panel,
    .middle-panel,
    .right-panel {
        min-height: 180px;
        max-height: none;
    }
    
    .panel {
        max-height: 85vh;
    }
    
    .panel-body {
        max-height: calc(85vh - 40px);
    }
    
    .chart-panel {
        min-height: 200px;
        max-height: 85vh;
    }
}

/* PWA 和全屏模式优化 */
@media (display-mode: standalone) {
    body {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }
}

/* 深色模式支持 */
@media (prefers-color-scheme: dark) {
    /* 已经是深色主题，无需额外处理 */
}

/* 减少动画（针对用户偏好） */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
